package br.eng.eliseu.gwt.aconchego.camera.server;


import java.util.Calendar;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import br.eng.eliseu.gwt.aconchego.camera.module.Usuario;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;

public class SecureRemoteServiceServlet extends RemoteServiceServlet{
	private static final long serialVersionUID = 2289148948352553778L;

	public Usuario getUser(){
		return SessionHelper.getUser(getThreadLocalRequest().getSession());
	}
	public void setUser(Usuario user){
		HttpServletRequest req = getThreadLocalRequest();
		HttpSession session = req.getSession(true);
		SessionHelper.setUser(session, user);
	}
	
	public Date fixDate(Date date){
		Calendar d = Calendar.getInstance();
		d.setTime(date);
		if(d.get(Calendar.HOUR_OF_DAY)>0){
			d.set(Calendar.HOUR_OF_DAY, 24);
		}
		d.set(Calendar.MINUTE, 0);
		d.set(Calendar.SECOND, 0);
		d.set(Calendar.MILLISECOND, 0);
		return d.getTime();
	}
}